﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DSDCiZharp.Models.Login;
using DSDCiZharp.Models.Reserva;

namespace DSDCiZharp.Controllers
{
    public class LoginController : Controller
    {
        //
        // GET: /Login/

        public ActionResult Login()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Login(string DNI, string pwd)
        {
            LoginModel loginModel = new LoginModel() {  DNI = DNI, Password = pwd};

            var cliente = new ClienteServiceReference.ClienteServiceClient().Logear(DNI, pwd);

            if (cliente != null)
            {
                Session["Id_Cliente"] = new Cliente() { DNI = cliente.DNI, ID_CLIENTE = cliente.ID_CLIENTE, NOMBRE_COMPLETO = cliente.NOMBRE_COMPLETO };

                return RedirectToAction("Index", "Venta");
            }
            else
            {
                ViewData["ErrorLogin"] = "Login Incorrecto";
                return View("Login");
            }
            
        }

        public ActionResult LogOut()
        {
            Session.Remove("Id_Cliente");

            return RedirectToAction("Index", "Venta");
        }

    }
}
